package utils;

import java.util.HashMap;
import java.util.Map;

//实现链式调用
public class MapParameter {
    private Map<String,Object> paramMap=new HashMap<String, Object>();
    //不能被外界new
    private MapParameter(){}
    //只提供一个获取对象的静态方法
    public static MapParameter getInstance(){
        return new MapParameter();
    }

    public Map<String ,Object> getMap(){
        return paramMap;
    }

    public MapParameter put(String key,Object val){
        paramMap.put(key, val);
        return this;
    }

    public MapParameter put(Map<String,Object> map){
        for (Map.Entry<String, Object> entry:map.entrySet()){
            paramMap.put(entry.getKey(),entry.getValue());
        }
        return this;
    }
    public MapParameter putId(Object val){
        return this.put("id",val);
    }
    //外界使用
    public static void main(String[] args) {
        Map<String, Object> map = MapParameter.getInstance().put("name", "yolin").put("age", "20").getMap();
        System.out.println(map);
    }
}
